All Questions
Tagged with arrayecmascript-6
41 questions
1vote
1answer
140views
Transform an array into object and set index for an unique key in javascript
I have a method that merges keys and indexes from an array into an object. I'm stuck with ways to compress this method, and I don't know what I can do to make it simpler. Goal get an array of objects ...
3votes
1answer
83views
Function that sorts nestedArray[][]'s
I'm fairly new to coding and am trying to learn more about best practices. I wanted to have an nestedArray of objectArrays, and I wanted to be able to sort the elements in each objectArray based on ...
3votes
1answer
204views
Randomly set styles with JavaScript
I have created a function which randomly sets styles using CSS selectors. Right now it returns a random item from an array. The program also works with shorthand properties (such as ...
4votes
2answers
575views
File naming (two files cannot have equal names)
This is a challenge I completed at CodeSignal. You are given an array of desired filenames in the order of their creation. Since two files cannot have equal names, the one which comes later will have ...
11votes
4answers
3kviews
Restructuring JSON to create a new JSON where properties are grouped according to similar values
I have a JSON structure in the following example format: ...
2votes
2answers
47views
Combine data from array of objects
I got this data structure and I am checking to see which properties are true, then I am adding the key for all the properties that are true to that object on a new ...
1vote
2answers
767views
Recursively find data in array of objects
On this script I look up properties in an array of objects. There is an original array of strings list to get the objects that match the ...
1vote
1answer
4kviews
Add / Overwrite an object in an array
I am trying to overwrite an object in an array if the title property exists, otherwise just push it to the array. I found two approaches and I wonder which one is ...
6votes
1answer
357views
JavaScript: A drawing program in OOP
I made a little drawing program in OOP. The game consists of a canvas which is basically a 2d array where the user can draw various shapes on it. There can be multiple shapes overlapped on top of each ...
5votes
1answer
182views
Generate all partitions of a set of items
Here are the items: var item = ['a', 'b', 'c', 'd']; Desired output: ...
0votes
1answer
67views
Avoid the object/array check and treat the return value the same way with JavaScript spread operator?
I'm trying to implement a function (a template-helper function) which provides a simple merge-like functionality for both arrays and objects. The two functions are basically looks identical: ...
1vote
1answer
53views
Filtering Array Based on Element Values
Required to splice specific element value in an array based on the condition. Both the below code does the same job and yields the correct results. But couldn't figure out how to reduce coding ...
5votes
3answers
140views
Removing unneeded objects from an array before rendering
I'm making a function that adds a new object to an array and removes the oldest if it has reached a specific length. Click the button in the example below. All objects are drawn until its array ...
4votes
1answer
384views
Extract string list as array from an array of objects
Having the following array of objects of ingredients used by cooks ...
8votes
3answers
2kviews
Javascript split array into n subarrays, size of chunks don't matter
NOTE: This post was moved from stackoverflow as codereview.stackexchange is a better place to discuss the performance of this code problem/solution. I want to split ...